package com.kelvem.saas.workbanch.fsm.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.kelvem.saas.workbanch.fsm.core.EventContext;
import lombok.Data;
import lombok.ToString;

import java.util.Date;
import java.util.List;

/**
 * @author kelvem
 */
@Data
@ToString(callSuper = true)
public class Entity {

    @TableId(type = IdType.AUTO)
    protected Long id;
    
    @TableField
    protected Date createTime;
    @TableField
    protected Date updateTime;
    @TableField
    protected String createUid;
    @TableField
    protected String updateUid;
    
    
    public <T> T selectOne() {
        
        return (T) EventContext.getEntity(this.getClass());
    }
    
    public <T extends Entity> T selectOne(Class<T> clazz) {
        
        return (T)EventContext.getEntity(clazz);
    }
    
    public <T extends Entity> T selectOne(Class<T> clazz, Long id) {
        // todo 待实现
        return null;
    }
    
    public <T extends Entity> List<T> selectList(Class<T> clazz) {
        
        return EventContext.getEntityList(clazz);
    }
    
    
    public static Entity instance() {
        return new Entity();
    }
    
    public static void print() {
        EventContext.print();
    }
}
